//*****************************************************************************
//
// Copyright, (C) 2000-2005 Quantic Dream SA
//
// These coded instructions, statements and computer programs contain
// unpublished information, proprietary to Quantic Dream SA and are 
// protected by French and EEC copyright laws. They may not be 
// disclosed to third parties or copied or duplicated, in whole or in part, 
// without prior written consent of Quantic Dream SA
//
// Unpublished-rights reserved under the Copyright Laws of the EEC.
//
//*****************************************************************************
//
//	CLASS:	MESH
//	The MESH class implements ...
//
//	JJA : 2012-07-23 - Created
//*****************************************************************************

//=============================================================================
//	CODE STARTS HERE
//=============================================================================

#ifndef MESH_H
#define MESH_H

#include <gl/glew.h>
#include "Transform/Transform.h"

#include	<QVector>

class QByteArray;

struct MESH_VERTEX
{
	VECTOR4	_vPosition;
	VECTOR4	_vColor;
	VECTOR4	_vNormal;
	POINT3	_vTexCoord;
};

enum VERTEX_ATTRIB_ID
{
	VERTEX_ATTRIB_POSITION,
	VERTEX_ATTRIB_COLOR,
	VERTEX_ATTRIB_NORMAL,
	VERTEX_ATTRIB_UV,

	VERTEX_ATTRIB_ID_MAX
};

class	MESH: public TRANSFORM
{
public:
					MESH();
					~MESH();

	void			Load( const QByteArray* pMeshData );
	void			LoadObjFile( const char* pObjFilePath );

	MESH_VERTEX*	GetMeshVertex( const uint uiIndex );

	void			Bind() const;
	void			Unbind() const;
	void			Draw() const;

private:
	struct OBJ_FACE_POINT
	{
		uint _uiVertexIndex;
		uint _uiNormalIndex;
		uint _uiTexCoordIndex;

		bool operator==( const OBJ_FACE_POINT& Other )
		{
			return	( ( Other._uiVertexIndex == _uiVertexIndex ) &&
					( Other._uiNormalIndex == _uiNormalIndex ) &&
					( Other._uiTexCoordIndex == _uiTexCoordIndex ) );
		}
	};

	GLuint			_uiVertexArrayId;
	GLuint			_uiElementArrayId;
	GLuint			_uiVertexBufferId;

	GLuint			_uiVerticesCount;
	uint			_uiElementsCount;
	
	uint*			_puiElementIndices;
	MESH_VERTEX*	_pcMeshData;
};

#endif // MESH_H

//=============================================================================
//	CODE ENDS HERE
//=============================================================================
